﻿using Dapper;
using SqlKata;

namespace Zws.Dapper.Interfaces
{
    public interface IDapperRepository<TEntity> where TEntity : BaseEntity
    {
        /// <summary>
        /// 批量查,查单个标量值，如总数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        Task<int> CountAsync(Query query);


        /// <summary>
        /// 查询单条
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        Task<T?> QuerySingleAsync<T>(Query query) where T : class;
        /// <summary>
        /// 查询多条
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        Task<List<T>> QueryAsync<T>(Query query) where T : class;

        /// <summary>
        /// 获取实体查询对象
        /// </summary>
        Query GenerateSqlQuery();
        Task<int> EntityCountAsync(Func<Query, Query>? condition = null);
        Task<TEntity?> EntityQuerySingleAsync(Func<Query, Query>? condition = null, params string[]? columns);
        Task<List<TEntity>> EntityQueryAsync(Func<Query, Query>? condition = null, params string[]? columns);
        Tuple<string, DynamicParameters?> QueryToSql(Query query);
        Task ExecuteAsync(Query query);
        Query SelectColumnQuery(Func<Query, Query>? condition = null, params string[]? columns);
        Query CountQuery(Func<Query, Query>? condition = null);
        Task<bool> EntityIsExistAsync(Func<Query, Query>? condition = null);
    }
}
